<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <title>城市名定位</title>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
</head>

<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>体检机构管理
            <small>体检机构地址管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>体检机构管理</el-breadcrumb-item>
            <el-breadcrumb-item>体检机构地址管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="项目编码/项目名称" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPages()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="体检机构名" align="center"></el-table-column>
                <el-table-column prop="telephone" label="联系电话" align="center"></el-table-column>
                <el-table-column prop="latitude" label="经纬度" align="center"></el-table-column>
                <el-table-column prop="imageUrl" label="机构图片" align="center"></el-table-column>
                <el-table-column prop="address" label="详细地址" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination class="pagiantion" @current-change="handleCurrentChange"
                               :current-page="pagination.currentPage" :page-size="pagination.pageSize"
                               layout="total, prev, pager, next, jumper" :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增体检" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="体验机构名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="联系电话" prop="telephone">
                                    <el-input v-model="formData.telephone"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="上传图片">
                                    <el-upload
                                            class="avatar-uploader"
                                            action="/setmeal/upload.do"
                                            :auto-upload="autoUpload"
                                            name="imgFile"
                                            :show-file-list="false"
                                            :on-success="handleAvatarSuccess"
                                            :before-upload="beforeAvatarUpload">
                                        <img v-if="imageUrl" :src="imageUrl" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="20">
                                <el-form-item label="经纬度">
                                    <el-input v-model="formData.latitude" id="result_"  type="text"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="20">
                            <el-col :span="12">
                                <el-form-item label="详细地址">
                                    <el-input v-model="formData.address" id="text_" type="text"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-button type="primary" icon="el-icon-location-outline" @click="searchByStationName">设置定位</el-button>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <div style="width:730px;margin:auto;">
                                    <div id="container">
                                    </div>
                                </div>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑体检" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="体验机构名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="联系电话" prop="telephone">
                                    <el-input v-model="formData.telephone"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="上传体验机构地址图片">
                                    <el-upload class="avatar-uploader"
                                               action="https://jsonplaceholder.typicode.com/posts/"
                                               :show-file-list="false"
                                               :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                                        <img v-if="imageUrl" :src="imageUrl" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="20">
                                <el-form-item label="经纬度">
                                    <el-input v-model="formData.latitude" id="result_"  type="text"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="20">
                            <el-col :span="12">
                                <el-form-item label="详细地址">
                                    <el-input v-model="formData.address" id="text_" type="text"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-button type="primary" icon="el-icon-location-outline" @click="searchByStationName">设置定位</el-button>
                            </el-col>
                        </el-row>

                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script type="text/javascript">
    var map = new BMap.Map("container");
    map.centerAndZoom("宁波", 12);
    map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用

    map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
    map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
    map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));   //右下角，打开

    var localSearch = new BMap.LocalSearch(map);
    localSearch.enableAutoViewport(); //允许自动调节窗体大小

</script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            imageUrl:null,//模型数据，用于上传图片完成后图片预览
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false, //编辑表单是否可见
            rules: {//校验规则
                telephone: [{required: true, message: '联系电话为必填项', trigger: 'blur'}],
                name: [{required: true, message: '机构名称为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage()
        },
        methods: {
            //编辑
            handleEdit() {
                this.$refs['dataEditForm'].validate(function (val) {
                    if (val) {
                        axios.post("/order_address/updateOne.do", vue.formData).then(function (res) {
                            vue.dialogFormVisible4Edit = false
                            if (res.data.flag) {
                                vue.$message({
                                    message: res.data.message,
                                    type: 'success'
                                })
                            } else {
                                vue.$message.error(res.data.message)
                            }
                        }).finally(function () {
                            vue.findPage()
                        })
                    }
                })
            },
            searchByStationName() {
                map.clearOverlays();//清空原来的标注
                var keyword = document.getElementById("text_").value;
                localSearch.setSearchCompleteCallback(function (searchResult) {
                    var poi = searchResult.getPoi(0);
                    document.getElementById("result_").value = poi.point.lng + "," + poi.point.lat;
                    vue.formData.latitude = poi.point.lng + "," + poi.point.lat;
                    map.centerAndZoom(poi.point, 13);
                    var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat));  // 创建标注，为要查询的地方对应的经纬度
                    map.addOverlay(marker);
                    var content = document.getElementById("text_").value + "<br/><br/>经度：" + poi.point.lng + "<br/>纬度：" + poi.point.lat;
                    var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
                    marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); });
                    // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
                });
                localSearch.search(keyword);
            },
            //文件上传成功后的钩子，response为服务端返回的值，file为当前上传的文件封装成的js对象
            handleAvatarSuccess(response, file) {
                this.$message({
                    type:response.flag==true?'success':'error',
                    message:response.message
                })
                this.imageUrl ='http://qa5pqxlln.bkt.clouddn.com/'+ response.data
                this.formData.imageUrl = response.data
            },
            //上传图片之前执行
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;
                if (!isJPG) {
                    this.$message.error('上传套餐图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传套餐图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            },
            //添加
            handleAdd() {
                this.$refs['dataAddForm'].validate(function (val) {
                    if (val) {

                        axios.post("/order_address/add.do", vue.formData).then(function (res) {
                            vue.dialogFormVisible = false
                            if (res.data.flag) {
                                vue.$message({
                                    message: res.data.message,
                                    type: 'success'
                                })
                            } else {
                                vue.$message.error(res.data.message)
                            }
                            vue.pagination.currentPage = 1
                            vue.findPage()
                        })
                    } else {
                        vue.$message.error("草拟吗,给老子规范点")
                    }
                })
            },
            //分页查询
            findPages() {
                this.pagination.currentPage = 1
                this.findPage()
            },
            findPage() {
                axios.post("/order_address/selectAllByName.do", this.pagination).then(function (res) {
                    if (res.data.total == 0) {
                        vue.$message.error("您输入有误,请重新输入")
                    } else {
                        vue.pagination.total = res.data.total
                        vue.dataList = res.data.rows
                    }
                })
            },
            // 重置表单
            resetForm() {
            },
            // 弹出添加窗口
            handleCreate() {
                this.imageUrl = ''
                this.formData = {}
                this.dialogFormVisible = true
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.formData = row
                this.imageUrl = 'http://qa5pqxlln.bkt.clouddn.com/'+row.imageUrl
                this.dialogFormVisible4Edit = true
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage
                this.findPage()
            },
            // 删除
            handleDelete(row) {
                this.$confirm("此操作将永久删除该文件, 是否继续?", "警告", {
                    type: "warning"
                }).then(function () {
                    axios.get("/order_address/deleteById.do?id=" + row.id).then(function (res) {
                        if (res.data.flag) {
                            vue.$message({
                                type: 'success',
                                message: res.data.message
                            })
                            vue.findPage()
                        } else {
                            vue.$message.error(res.data.message)
                        }
                    }).catch(function (res) {
                        vue.$message.error(res.data.message)
                    })
                }).catch(function () {
                    vue.$message.error("草泥马,不删除乱点尼玛")
                })
            },
            changeStatus() {
                this.dialogFormVisible4Edit = true;
            }
        }
    })
</script>
<style>
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }

    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
</style>


</html>